/**
 * Created by yanxiaoyao on 17/03/03.
 */
'use.strict';
define(['angular', 'require', 'ui-router', 'page', 'angular-toastr', 'angular-toastr-tpls'], function() {
    var app = angular.module('myApp', ['ui.router', 'base', 'toastr']);
    app.run(function($rootScope, $state) {
        $rootScope.select = "";
        $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
            $rootScope.select = toState.name;
            //              console.log(toState.name)
        })
    })
    app.config(function($controllerProvider, $compileProvider, $filterProvider, $provide) {
            app.register = {
                //得到$controllerProvider的引用
                controller: $controllerProvider.register,
                //同样的，这里也可以保存directive／filter／service的引用
                directive: $compileProvider.directive,
                filter: $filterProvider.register,
                service: $provide.service
            };
        })
        .config(function(toastrConfig) {
            angular.extend(toastrConfig, {
                autoDismiss: false,
                containerId: 'toast-container',
                maxOpened: 0,
                newestOnTop: true,
                positionClass: 'toast-top-center',
                preventDuplicates: false,
                preventOpenDuplicates: true,
                target: 'body'
            });
        })
        .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
            $urlRouterProvider.otherwise('/main');
            $stateProvider
                .state('main', {
                    url: '/main',
                    views: {
                        '': {
                            templateUrl: "/tpls/main.html"
                        },
                        'comHeader@main': {
                            templateUrl: "/tpls/common/header.html",
                            controller: "headctrl",
                            resolve: {
                                headctrl: ["$q", function($q) {
                                    var deferred = $q.defer();
                                    //异步加载controller／directive/filter/service
                                    require([
                                        './controller/head/head'
                                    ], function() { deferred.resolve(); });
                                    return deferred.promise;
                                }]
                            }
                        },
                        'comContent@main': {
                            templateUrl: "/tpls/main/main.html",
                        }

                    }
                })
                // VINTable开始
                .state("main.vinCarType", {
                    url: "/vinCarType?vinCode",
                    views: {
                        "comContent@main": {
                            templateUrl: "/tpls/vinCarType/vinCarType.html",
                            controller: "vinCarType",
                            resolve: {
                                selectCar: ["$q", function($q) {
                                    var deferred = $q.defer();
                                    //异步加载controller／directive/filter/service
                                    require([
                                        './controller/head/vinCarType'
                                    ], function() { deferred.resolve(); });
                                    return deferred.promise;
                                }]
                            }
                        }
                    }
                })
                // noticeTable 公告号开始
                .state("main.noticeNumber", {
                    url: "/noticeNumber?noticeCode",
                    views: {
                        "comContent@main": {
                            templateUrl: "/tpls/noticeNumber/noticeNumber.html",
                            controller: "noticeNumber",
                            resolve: {
                                selectCar: ["$q", function($q) {
                                    var deferred = $q.defer();
                                    //异步加载controller／directive/filter/service
                                    require([
                                        './controller/head/noticeNumber'
                                    ], function() { deferred.resolve(); });
                                    return deferred.promise;
                                }]
                            }
                        }
                    }
                })
                //              详情页开始
                .state("main.selectCar", {
                    url: "/selectCar?threeId?twoId?oneId?txtoemId?partsId",
                    views: {
                        "comContent@main": {
                            templateUrl: "/tpls/selectCar/selectCar.html",
                            controller: "selectCar",
                            resolve: {
                                selectCar: ["$q", function($q) {
                                    var deferred = $q.defer();
                                    //异步加载controller／directive/filter/service
                                    require([
                                        './controller/selectCar/selectCar'
                                    ], function() { deferred.resolve(); });
                                    return deferred.promise;
                                }]
                            }
                        }
                    }
                })
                //               详情页结束
                //              生成询价单开始
                .state("main.inquirySheet", {
                    url: "/inquirySheet?threeId?twoId?oneId?partsId",
                    views: {
                        "comContent@main": {
                            templateUrl: "/tpls/inquirySheet/inquirySheet.html",
                            controller: "inquirySheet",
                            resolve: {
                                inquirySheet: ["$q", function($q) {
                                    var deferred = $q.defer();
                                    //异步加载controller／directive/filter/service
                                    require([
                                        './controller/selectCar/inquirySheet'
                                    ], function() { deferred.resolve(); });
                                    return deferred.promise;
                                }]
                            }
                        }
                    }
                })
                //               生成询价单结束

        }])
    return app;
});
